package homework05;

import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;

	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public String toString() {
		return name+"-"+age;
	}

	public int compareTo(PersonSortable o) {
		 int result = 0;
	        result =  this.name.compareTo(o.name);
	        if(0==result){
	            result = this.age-o.age;
	        }
	        return result;
	}
}

public class Seven01 {
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		String N=sc.nextLine();
		int n = Integer.parseInt(N);
		PersonSortable[] pers = new PersonSortable[n];
		for(int i=0;i<n;i++)
		{
			
			pers [i]=new PersonSortable(sc.next(), sc.nextInt());
		}
		Arrays.sort(pers);
		for(int i=0;i<n;i++)
		{
			System.out.println(pers[i].toString());
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		sc.close();
	}
}
